"insert into news (c_title,c_aythor,c_source,c_content) values("+ title+"," +author+","+source+","+context+")"

解决方案 »

  1.   

    我没有说清楚,
    我是说从和数据库建立连接开始,
    我不知道用哪些组件
    我建立了oleDbConnection,oleDbCommand,DataSet,OleDbDataAdapter,不知道怎么用
      

  2.   

    oleDbConnection的设置没有问题,
    this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
    this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand();
    // 
    // oleDbConnection1
    // 
    this.oleDbConnection1.ConnectionString = @"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=HightechZone;Data Source=TECH\TECH;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=TEC001;Use Encryption for Data=False;Tag with column collation when possible=False";
    // 
    // oleDbCommand1
    // 
    this.oleDbCommand1.CommandText ="SELECT app_news.* FROM app_news";
    this.oleDbCommand1.Connection = this.oleDbConnection1;
    这个我试过了,可以读出来,
    我就是不会插入
      

  3.   

    this.oleDbCommand1.CommandText ="insert into news (c_title,c_aythor,c_source,c_content) values("+ title+"," +author+","+source+","+context+")"
    this.oleDbCommand1.Excutenoquery()
      

  4.   

    DataSet,OleDbDataAdapter还要不要啊,
    哪位大哥给个完整点的例子
      

  5.   

    存储过程:
    --------------------------------------------------------
    Create Procedure pPageLoadInsertor --这里是存储过程名字
    (
    @Title nvarchar(100),
    @Author nvarchar(100),
    @Source nvarchar(100),
    @Content nvarchar(100),--这个是插入记录获取该记录的ID号,插入失败则返回-1
    @ID int output
    )
    As
    Begin Transaction
        Insert Into news (
            Title,--对应字段
            Author,
            Source,
            Content)
        Values(
            @Title,
            @Author,
            @Source,
            @Content)
    Commit Transaction
    If @@Error <> 0
        Begin
            Select @ID=-1
            RollBack Transaction
        End
    Else
        Begin
            Select @ID = @@Identity
        EndGo
    -----------------------存储过程结束--------------------------------对象:文件名  MyClass.vb 假设项目对象名为WebApplication1
    '从这里开始
    Imports System.Data.SqlClient
    Public Class MyClass
        Public Sub New()
        End Sub    Public Function InsertProc(strTitle as string,strAuthor as string,strSource as string,strContext as string)
                Dim MyConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))'在webconfig中定义的SQl连接
                Dim MyCommand As New SqlCommand("pAddNewEmployment", MyConnection)            MyCommand.CommandType = CommandType.StoredProcedure            Dim paramTitle As New SqlParameter("@Title", SqlDbType.NVarChar, 100)
                paramTitle.Value = strTitle
                MyCommand.Parameters.Add(paramTitle)            Dim paramAuthor As New SqlParameter("@Author", SqlDbType.NVarChar, 100)
                paramAuthor.Value = strAuthor
                MyCommand.Parameters.Add(paramAuthor)            Dim paramSource As New SqlParameter("@Source", SqlDbType.NVarChar, 100)
                paramSource.Value = strSource
                MyCommand.Parameters.Add(paramSource)            Dim paramContent As New SqlParameter("@Content", SqlDbType.NVarChar, 100)
                paramContent.Value = strContent
                MyCommand.Parameters.Add(paramContent)            Dim paramID As New SqlParameter("@ID", SqlDbType.Int)
                paramID.Direction = ParameterDirection.Output
                MyCommand.Parameters.Add(paramID)            MyConnection.Open()
                MyCommand.ExecuteNonQuery()
                MyConnection.Close()            Return paramID.Value
        End Function
    End Class
    ’到这里结束在程序中需要使用该对象的地方:
    ‘从这里开始
    Dim MyTestClass as New WebApplication1.MyClass
    If MyTestClass.InsertProc(c_title,c_aythor,source,c_content) >0 Then  '这里输入要输入的4个字符串
    '这里放上要获得的结果
    End If
    '到这里结束
    简单吧,应用层只需要3行代码
    虽然上面代码比较多,但是层次比较清晰。
    好好研究吧
      

  6.   

    dim con as oledb.oledbconnection
    dim com as oledb.oledbcommandcon= new oledb.oledbconnection("provider=microsoft.jet.oledb.4.0;data source=c:\db1.mdb")str ="insert into table (id ,name,age) values ('009','www',30)"
    com=new oledb.oledbcommand(str,con)
    con.open()com.Excutenoquery()
    con.close()如 此 写 没 问 题 !
      

  7.   

    //我见了这么个页面
    回复人:janssenkm(^_^100) () 信誉:100  2003-4-3 13:32:11 得分: 4 删除  
     
      存储过程:  
    --------------------------------------------------------  
    Create  Procedure  pPageLoadInsertor  --这里是存储过程名字  
    (  
    @Title  nvarchar(100),  
    @Author  nvarchar(100),  
    @Source  nvarchar(100),  
    @Content  nvarchar(100