server unity连接sql_急用求助unity 3d 如何连接sql server?

在Unity 3D游戏中,开发者尝试将玩家得分(coins)存储到SQL Server数据库中。使用SqlConnection和SqlCommand进行数据库连接,并尝试执行存储过程`insertmark`来插入数据。遇到问题,寻求帮助。代码中展示了如何初始化数据库连接,打开连接,执行SQL命令以及关闭连接的过程。
摘要由CSDN通过智能技术生成

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

最近做作业时碰见的一个问题

需要将游戏是=时产生的一个分数变量coins导入数据库game,部分代码如下:大神帮我看看有神马问题

using UnityEngine;

using System;

using System.Data;

using System.Collections;

using System.Data.SqlClient;

public class mark : MonoBehaviour {

// Use this for initialization

void Start () {

SqlConnection sqlcon = new SqlConnection (

//"server=PC-20140516VZMW;" +

"data source=localhost;user id=sa;password=123456; initial catalog =game"); //name of database

SqlCommand cmd=new SqlCommand();

cmd.Connection = sqlcon;

cmd.CommandType = System.Data.CommandType.Text;

//sql connection

cmd.CommandText = " USE game GO EXEC insertmark @mark=coins;";//执行存储过程insertmark

SqlDataAdapter da = new SqlDataAdapter (cmd);

da.SelectCommand.Connection.Open ();

string tempip =

da.SelectCommand.ExecuteScalar ().ToString ();

da.SelectCommand.Connection.Close ();

print ("get" + tempip);

}

void CollectCoin(Collider2D coinCollider)

{

coins++;

Destroy(coinCollider.gameObject);

AudioSource.PlayClipAtPoint(coinCollectSound, transform.position);

}

void DisplayCoinsCount() //游戏界面显示分数

{

Rect coinIconRect = new Rect(10, 10, 32, 32);

GUI.DrawTexture(coinIconRect, coinIconTexture);

GUIStyle style = new GUIStyle();

style.fontSize = 30;

style.fontStyle = FontStyle.Bold;

style.normal.textColor = Color.yellow;

Rect labelRect = new Rect(coinIconRect.xMax, coinIconRect.y, 60, 32);

GUI.Label(labelRect, coins.ToString(), style);

}

// Update is called once per frame

void Update () {

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值